package org.yray.netty.demo;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;

public class ChannelDelimiterClient extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //字符串编码器
        //channel.pipeline ().addLast (new StringEncoder ());
        //long编码器
//                            channel.pipeline ().addLast (new OutEncoder ());
        ByteBuf delimiter = Unpooled.copiedBuffer ("$_$".getBytes ());
        ch.pipeline ().addLast (new DelimiterBasedFrameDecoder(1024, delimiter));
        //加入处理器
        ch.pipeline ().addLast (new NettyClientHandler ());
    }
}
